<!DOCTYPE HTML>
<html>

<head>
    <title>proton.js-render-EaseljsRender</title>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <style type="text/css">
        body {
            background-color: #333333;
            margin: 0px;
            overflow: hidden;
        }

        #container {
            width: 1003px;
            margin-top: 50px;
            margin-left: -501px;
            left: 50%;
            position: absolute;
        }

        #testCanvas {
            background: #000000;
        }
    </style>
    <script src="../../lib/requestAnimationFrame.min.js"></script>
    <script src="../../lib/stats.min.js"></script>
    <script src="../../lib/easeljs-0.8.2.min.js"></script>
    <script src="../../lib/preloadjs-0.6.2.min.js"></script>
    <script src="//localhost:3001/build/proton.js"></script>
</head>

<body>
    <div id="container">
        <canvas id="testCanvas"></canvas>
    </div>
    <script>
        var canvas;
        var stage;
        var proton;
        var bitmap;
        var renderer;
        var stats;

        main();

        function main() {
            canvas = document.getElementById("testCanvas");
            canvas.width = 1003;
            canvas.height = 610;
            stage = new createjs.Stage(canvas);
            bitmap = new createjs.Bitmap('image/daisy.png');
            addStats();

            createProton();

            createjs.Ticker.timingMode = createjs.Ticker.RAF;
            createjs.Ticker.addEventListener("tick", tick);
        }

        function addStats() {
            stats = new Stats();
            stats.setMode(2);
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.left = '0px';
            stats.domElement.style.top = '0px';
            document.getElementById("container").appendChild(stats.domElement);
        }

        function createProton() {
            proton = new Proton();
            emitter = new Proton.Emitter();
            emitter.rate = new Proton.Rate(new Proton.Span(30, 40), new Proton.Span(.5, 2));
            emitter.addInitialize(new Proton.Body(bitmap));

            emitter.addInitialize(new Proton.Mass(1, 5));
            emitter.addInitialize(new Proton.Radius(20));
            emitter.addInitialize(new Proton.Life(100));
            emitter.addInitialize(new Proton.Position(new Proton.LineZone(0, -40, canvas.width, -40)));
            emitter.addInitialize(new Proton.V(0, new Proton.Span(.1, 1)));

            emitter.addBehaviour(new Proton.CrossZone(new Proton.LineZone(-300, canvas.height + 40, canvas.width + 300, canvas.height + 40, 'down'), 'dead'));
            emitter.addBehaviour(new Proton.Rotate(new Proton.Span(0, 360), new Proton.Span(-.5, .5), 'add'));
            emitter.addBehaviour(new Proton.Scale(new Proton.Span(.2, 1)));
            emitter.addBehaviour(new Proton.RandomDrift(10, 0, .09));
            emitter.addBehaviour(new Proton.Gravity(0.9));

            proton.addEmitter(emitter);
            emitter.emit();

            renderer = new Proton.EaselRenderer(stage);
            proton.addRenderer(renderer);

            emitter.preEmit(20);
        }

        function tick() {
            stats.begin();
            proton.update();
            proton.stats.update(2);
            stage.update();
            stats.end();
        }
    </script>
</body>

</html>